package top.malaoshi.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.entity.User;
import top.malaoshi.model.JsonResult;
import top.malaoshi.service.UserSrvImpl;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginCtrl {

    @Resource
    private UserSrvImpl srv;

    @PostMapping("/login")
    public JsonResult queryByUsername(String username, String password, HttpSession session){
        JsonResult res=new JsonResult(0,"登录成功！");
        User user=srv.queryByUsername(username);

        Map map=new HashMap();
        map.put("id",user.getId());
        map.put("username",user.getUsername());
        res.setData(map);
        session.setAttribute("user",user);
        return res;

    }
}
